using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class JobSeekers_action : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (PreviousPage == null)
        {
            this.lblHeader.Text = "Sorry, you are doing nothing";
        }
        else
        {
            string jsemail = Convert.ToString(Session["jsemail"]);
            SQLServerClass cls = new SQLServerClass();
            Page page = PreviousPage;
            
            HiddenField hiddenField = (HiddenField)page.FindControl("hdfAction");
            TextBox textBox1,textBox2,textBox3,textBox4 ;
            switch (hiddenField.Value)
            {
                case "CPWD":
                    this.lblHeader.Text = "Change password";
                    textBox1 =(TextBox)page.FindControl("txtOldPassword");
                    textBox2 =(TextBox)page.FindControl("txtPassword");
                    if(cls.ChangePassword(jsemail,textBox1.Text, textBox2.Text))
                        Literal1.Text ="Change password successfull.";
                    else
                        Literal1.Text = "Sorry, can not change password. "
                        + cls.ErrorMessage;
                    break;
                case "FGPWD":
                    this.lblHeader.Text = "Forgot password";
                    textBox1 = (TextBox)page.FindControl("txtEmail");
                    textBox2 = (TextBox)page.FindControl("txtFirstName");
                    textBox3 = (TextBox)page.FindControl("txtLastName");
                    textBox4 = (TextBox)page.FindControl("txtDOB");
                    string password= 
                    cls.ForgotPassword(
                    textBox1.Text, textBox2.Text+ " " + textBox3.Text, textBox4.Text);
                    if(cls.ErrorMessage=="" && password!="")
                    {
                        MailClass mailClass = new MailClass();
                        mailClass.SendMail(textBox1.Text, 
                        "Forgot password", " Here is your new password: " + password);
                        Literal1.Text = "Send password to your email successfull.";
                    }
                    else
                    Literal1.Text = "Sorry, can not send password to you. "
                        + cls.ErrorMessage;
                    break;
            }
        }
    }
}
